package com.cls.business.service.impl;

import com.cls.common.entity.QueryRequest;
import com.cls.business.entity.MemberInfoRecord;
import com.cls.business.mapper.MemberInfoRecordMapper;
import com.cls.business.service.IMemberInfoRecordService;
import com.cls.common.utils.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import lombok.RequiredArgsConstructor;
import com.github.pagehelper.PageHelper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Arrays;
import java.util.List;

/**
 * 委托课题审核成员变动记录信息表 Service实现
 *
 * @author slx
 * @date 2020-12-02 14:27:30
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class MemberInfoRecordServiceImpl extends ServiceImpl<MemberInfoRecordMapper, MemberInfoRecord> implements IMemberInfoRecordService {

    @Override
    public PageInfo<MemberInfoRecord> findMemberInfoRecords(QueryRequest request, MemberInfoRecord memberInfoRecord) {
        LambdaQueryWrapper<MemberInfoRecord> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        if(memberInfoRecord.getMemberType()!=null){
          queryWrapper.eq(MemberInfoRecord::getMemberType,memberInfoRecord.getMemberType());
        }
        if(memberInfoRecord.getDeclareId()!=null){
            queryWrapper.eq(MemberInfoRecord::getDeclareId,memberInfoRecord.getDeclareId());
        }
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        List<MemberInfoRecord> list= this.list(queryWrapper);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public List<MemberInfoRecord> findMemberInfoRecords(MemberInfoRecord memberInfoRecord) {
	    LambdaQueryWrapper<MemberInfoRecord> queryWrapper = new LambdaQueryWrapper<>();
		// TODO 设置查询条件
        if(memberInfoRecord.getDeclareId()!=null){
            queryWrapper.eq(MemberInfoRecord::getDeclareId,memberInfoRecord.getDeclareId());
        }
        if(memberInfoRecord.getMemberType()!=null){
            queryWrapper.eq(MemberInfoRecord::getMemberType,memberInfoRecord.getMemberType());
        }
		return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createMemberInfoRecord(MemberInfoRecord memberInfoRecord) {
        this.save(memberInfoRecord);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateMemberInfoRecord(MemberInfoRecord memberInfoRecord) {
        this.saveOrUpdate(memberInfoRecord);
    }


    /**
    * 删除
    * @param ids
    */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteMemberInfoRecords(String[] ids) {
        List< String > list = Arrays.asList(ids);
        this.removeByIds(list);
     }

    @Override
    public List<MemberInfoRecord> findLogByDeclareId(Long declareId) {
        return this.baseMapper.findLogByDeclareId(declareId);
    }
}
